<template>
    <el-container>
        <el-header>
            <el-container>
                <PrimaryButton text="增加" :click="showAdd" />
                <SearchInput placeholder="请输入MU" :change="(value)=>handleChange(value,'mu')" />
                <SearchButton :click="search" />
            </el-container>
        </el-header>
        <el-main>
            <el-table stripe :data="tableData" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)" v-loading.fullscreen.lock="loading">
                <el-table-column prop="mu" label="编号" width="280" />
                <el-table-column prop="id" label="城市编号" width="180" />
                <el-table-column prop="name" label="城市名称" width="80" />
                <el-table-column prop="sort" label="城市排序" sortable width="115" />
                <el-table-column prop="createTime" label="创建时间" sortable width="220" />
                <el-table-column label="操作" width="200">
                    <template #={mu}>
                        <PlainButton text="编辑" :click="()=>showUpdate(mu)" />
                        <PlainButton text="删除" :click="()=>doDelete(mu)" />
                    </template>
                </el-table-column>
            </el-table>
            <SearchPagination :currentPage="currentPage" :total="total" :limit="limit" @handleCurrentChange="handleCurrentChange" @handleSizeChange="handleSizeChange" />
        </el-main>
        <el-footer>
            <el-dialog width="35%" title="添加" :visible="showAddForm">
                <el-form ref="form" :rules="rules" :model="form" label-width="100px">
                    <el-form-item label="城市名称" prop="name">
                        <el-input v-model="form.name" placeholder="请输入城市名称" />
                    </el-form-item>
                    <el-form-item label="城市排序" prop="sort">
                        <el-input v-model="form.sort" placeholder="请输入城市排序"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <PrimaryButton text="确定" :click="doAdd" />
                    </el-form-item>
                </el-form>
            </el-dialog>
            <el-dialog width="35%" title="修改" :visible="showUpdateForm">
                <el-form ref="updateForm" :rules="rules" :model="updateForm" label-width="100px">
                    <el-form-item label="城市名称" prop="name">
                        <el-input v-model="updateForm.name" placeholder="请输入城市名称" />
                    </el-form-item>
                    <el-form-item label="城市排序" prop="sort">
                        <el-input v-model="updateForm.sort" placeholder="请输入城市排序"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <PrimaryButton text="确定" :click="doUpdate" />
                    </el-form-item>
                </el-form>
            </el-dialog>
        </el-footer>
    </el-container>
</template>
<script>
import { page, remove, create, update } from '@/chaos/functions/mixin/crud';

export default {
    name: 'City',
    mixins: [page, remove, create, update],
    data() {
        const rules = {
            name: [
                { required: true, message: '请输入城市名称', trigger: 'blur' }
            ],
            sort: [{ required: true, message: '请输入排序', trigger: 'blur' }]
        };
        return {
            domain: 'iya_city',
            rules
        };
    },
    created() {
        this.search();
    }
};
</script>
<style lang="less" scoped>
.el-form {
    width: 500px;
}
</style>
